﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using EB.SQL;
/// <summary>
/// Summary description for paymentclass
/// </summary>
public class PaymentRequestHandler
{
    string _constring;
    int     _paymentType;
    string _paidTo;
    string _purpose;
   string _amount;
    string _billNo;
    string _billDate;
    string _billAmount;
    string  _balance;
    int     _paymentMode;
    string _orderNo;
    string _paymentDate;
     public static  int _idkey;
    //SqlConnection sqlcon = new SqlConnection();
    //SqlCommand sqqlcmd = new SqlCommand();
    SqlInsertHelper _sqlInserer = new SqlInsertHelper();
    

    public string Constring
    {
        get { return _constring; }
        set 
        {
            _constring = value;
            _sqlInserer.ConString = _constring;
        }
    }

    public int PaymentType
    {
        get { return _paymentType; }
        set 
        { 
            _paymentType = value;
            ValueDetails field = new ValueDetails(VariableType.Integer);
            field.Value = _paymentType.ToString();
            _sqlInserer.Fields.Add("PaymentType", field);
        }
    }
    public string PaidTo
    {
        get { return _paidTo; }
        set {
            _paidTo = value;
            ValueDetails field = new ValueDetails(VariableType.StringfValue);
            field.Value = _paidTo;
            _sqlInserer.Fields.Add("PaidTo", field);
        
        }
    }
    public string Purpose
    {
        get { return _purpose; }
        set { 
            _purpose = value;
            ValueDetails field = new ValueDetails(VariableType.StringfValue);
            field.Value = _purpose;
            _sqlInserer.Fields.Add("Purpose", field);
        
        }
    }
    public string Amount
    {
        get { return _amount; }
        set {
            _amount = value;
            ValueDetails field = new ValueDetails(VariableType.Integer);
            field.Value = _amount;
            _sqlInserer.Fields.Add("Amount ", field);
        
        
        }
    }
    public string BillNo
    {
        get { return _billNo; }
        set { 
            _billNo = value;
            ValueDetails field = new ValueDetails(VariableType.StringfValue);
            field.Value = _billNo;
            _sqlInserer.Fields.Add("BillNo", field);
        
        }
    }
    public string BillDate
    {
        get { return _billDate; }
        set {
            _billDate = value;
            ValueDetails field = new ValueDetails(VariableType.StringfValue);
            field.Value = _billDate;
            _sqlInserer.Fields.Add("BillDate ", field);
        
        
        }
    }
    public string BillAmount
    {
        get { return _billAmount; }
        set { 
            _billAmount = value;
            ValueDetails field = new ValueDetails(VariableType.Integer);
            field.Value = _billAmount;
            _sqlInserer.Fields.Add("BillAmount ", field);
        
        }
    }
    public string Balance
    {
        get { return _balance; }
        set {
            _balance = value;
            ValueDetails field = new ValueDetails(VariableType.Integer);
            field.Value = _balance;
            _sqlInserer.Fields.Add("Balance", field);
        
        }
    }
    public int PaymentMode
    {
        get { return _paymentMode; }
        set {
            _paymentMode = value;
            ValueDetails field = new ValueDetails(VariableType.Integer);
            field.Value = _paymentMode.ToString();
            _sqlInserer.Fields.Add("PaymentMode", field);
        }
    }
    public string OrderNo
    {
        get { return _orderNo; }
        set {
            _orderNo = value;
        ValueDetails field = new ValueDetails(VariableType.StringfValue);
        field.Value = _orderNo;
        _sqlInserer.Fields.Add("OrderNo", field);
                
        }
    }

    public string PaymentDate
    {
        get { return _paymentDate; }
        set { 
            _paymentDate = value;
            ValueDetails field = new ValueDetails(VariableType.StringfValue);
            field.Value = _paymentDate;
            _sqlInserer.Fields.Add("paymentdate", field);
        
        }
    }
    



    public PaymentRequestHandler()
    {



    }

    public int AddAPaymentRequest()
    {
        int id = 0;
        try
        {


            _sqlInserer.TableName = "PaymentRequestList";
            _sqlInserer.KeyPrimary = "PaymentID";
          id= _sqlInserer.ExecInsert();
           _idkey = id;
           return id;
        }

      



        catch (Exception ex)
        {
           //redirect to error page
           
        }
        return id;
        

    }

    public bool UpdatePaymentRequest()
    {
        //string _constring;
        //int _paymentType;
        //string _paidTo;
        //string _purpose;
        //string _amount;
        //string _billNo;
        //string _billDate;
        //string _billAmount;
        //string _balance;
        //int _paymentMode;
        //string _orderNo;
        //string _paymentDate;
        //int _idkey;
        try
        {
            SqlConnection sqlCon = new SqlConnection();
            SqlCommand sqlCommand = new SqlCommand();

            sqlCon.ConnectionString = _constring; ;
            sqlCommand.Connection = sqlCon;

            sqlCon.Open();
            string sqlCmd = "update  PaymentRequestList set  RequestID=0,PaymentType=" + _paymentType + ",PaidTo='" + _paidTo + "', Purpose='" + _purpose + "',Amount='" + _amount + "',BillNo='" + _billNo + "',BillDate='" + _billDate + "',BillAmount='" + _billAmount + "',Balance='" + _balance + "',PaymentMode=" + _paymentMode + ",OrderNo='" + _orderNo + "',paymentdate='" + _paymentDate + "' where PaymentID=" + _idkey + "";
            sqlCommand.CommandText = sqlCmd;
            sqlCommand.ExecuteNonQuery();
            sqlCon.Close();
            return true;

        }
        catch (Exception ex)
        {
            return false;
        }


    }

    public int GetPaymentMode(int requestId)
    {
        #region Fields
        string query = string.Empty;
        int requestTypeId = 0;
        EB.Generics.Generics commonClass = new EB.Generics.Generics();
        #endregion
        query = "select PaymentType from PaymentRequestList where PaymentID='" + requestId + "'";
        object requestTypeNo = commonClass.ExecuteScalar(query);
        if (requestTypeNo != "")
            requestTypeId = Convert.ToInt16(requestTypeNo);
        return requestTypeId;
    }



    public DataSet GetPaymentRequestByPaymentId(int requestId)
    {
        #region Fields
        string query = string.Empty;
        EB.Generics.Generics commonClass = new EB.Generics.Generics();
        #endregion

        query = "SELECT     PaidTo, Purpose, Amount, BillNo, BillDate, BillAmount, Balance, "+
                " PaymentMode, OrderNo, paymentdate, Status, PaymentType, RequestID "+
                " FROM  PaymentRequestList where PaymentID='"+requestId+"'";
        DataSet paymentDS = commonClass.ExecuteQuery(query);
        return paymentDS;

    }

    
}
